﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using EStore.Core.ValueObjects;

namespace EStore.Core.Orders
{
    public class Order : IAggregateRoot<Order, string, IOrderRepository>
    {
        public string ID { get; set; }

        public List<ProductForSale> Products { get; set; }

        public ShippingAddress ShippingAddress { get; set; }

        public DeliveryInfo DeliveryInfo { get; set; }

        public InvoiceInfo InvoiceInfo { get; set; }

        public PayInfo PayInfo { get; set; }

        public OrderStatus Status { get; private set; }

        public Money TotalPrice { get; private set; }

      
        public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            throw new NotImplementedException();
        }

        public bool CanBeSaved
        {
            get { throw new NotImplementedException(); }
        }

        //event OrderCreatedEvent @event;
        public void Save()
        {
            //Contract.Requires<InvalidOperationException>(CanBeSaved, string.Format("无法创建订单:{0}"));
            //TODO 触发订单创建事件
            //@event.
            throw new NotImplementedException();
        }

        [ContractInvariantMethod]
        private void ObjectInvariant()
        {
            //Contract.Invariant(TotalPrice.Amount.Equals(Items.Sum(p => p.SalePrice.Amount)));
        }
    }

    public class OrderItem : IEntity<int>
    {
        public int Quantity { get; private set; }

        public Money SalePrice { get; private set; }

        int IEntity<int>.ID
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
        {
            throw new NotImplementedException();
        }
    }
}
